package top.lidee.module.aggregat.controller;

import com.alipay.api.AlipayApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.lidee.common.param.TogetherPayParam;
import top.lidee.common.service.WeixinService;
import top.lidee.framework.result.ResponseResult;
import top.lidee.framework.web.BaseController;
import top.lidee.framework.web.ResponseObject;
import top.lidee.module.aggregat.service.ClientAggregatService;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


/**
 * 结算中心接口
 *
 * Created by FSQ
 * CopyRight https://www.lidee.top
 */
@Api(tags="聚合支付-订单结算相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/aggregatApi/settlement")
public class ClientAggregationController extends BaseController {



    @Autowired
    private ClientAggregatService aggregatService;

    /**
     * 聚合扫码支付入口
     */
    @ApiOperation(value = "提交订单结算")
    @RequestMapping(value = "/scan/pay", method = RequestMethod.POST)
    @CrossOrigin
    public ResponseObject scanPay(HttpServletRequest request, @RequestBody TogetherPayParam param) throws Exception {
        return aggregatService.doScanPay(request, param);
    }



    /**
     * 微信聚合扫码支付回调
     * */

    @ApiOperation(value = "微信聚合扫码支付回调")
    @RequestMapping(value = "/scan/wx/notify")
    @CrossOrigin
    public void wxScanNotify(HttpServletRequest request)  {
        aggregatService.handleWxNotify(request);
    }



    /**
     * 支付宝聚合扫码支付回调
     * */
    @ApiOperation(value = "支付宝聚合扫码支付回调")
    @RequestMapping(value = "/scan/aliPay/notify")
    @CrossOrigin
    public void aliPayScanNotify(HttpServletRequest request) throws AlipayApiException {
         aggregatService.handleAlipayNotify(request);
    }

    @Autowired
    private WeixinService weixinService;

    @ApiOperation(value = "微信小程序openID")
    @RequestMapping(value = "/openId/{code}", method = RequestMethod.POST)
    public ResponseResult getOpenId(@NonNull @PathVariable String code) throws IOException {
        return weixinService.getWxOpenId(code);
    }






























}
